﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MethodWorx.Core.DomainModel
{
    public class RepositoryRegistry : IRepositoryRegistry
    {

        private Dictionary<Type, IRepository> repositories;

        public RepositoryRegistry()
        {
            this.repositories = new Dictionary<Type, IRepository>();
        }

        public void RegisterRepository<TProxy, TEntity>(IRepository<TEntity> repository)
            where TEntity : AggregateRoot
            where TProxy : TEntity
        {
            if(!this.repositories.ContainsKey(typeof(TProxy)))
                this.repositories.Add(typeof(TProxy), repository);
            if(!this.repositories.ContainsKey(typeof(TEntity)))
                this.repositories.Add(typeof(TEntity), repository);
        }

        public IRepository GetRepository(Type type)
        {
            return repositories[type];
        }

    }
}
